home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / Sane.c < prev    next >
Text File  |  1993-02-23  |  2KB  |  55 lines

  1. /* Sane.c
  2. These routines provide more convenient access to the Apple provided routines
  3. that convert back and forth between 12-byte and 10-byte floating point formats.
  4. The two formats contain exactly the same information. The 12-byte format, used
  5. by the Motorola floating point chips, has an unused two byte gap between the
  6. exponent and mantissa.
  7.  
  8. These routines used to be in the IsNan.c file, but I found that I never used
  9. them, and I didn't like the fact that they force me to include the header
  10. SANE.h, so I put them here. Users of THINK C version 5 (or later) won't need to
  11. do these conversions if they use THINK's "universal" floating point format, which
  12. is compatible with BOTH the SANE library AND the Motorola chip.
  13.  
  14. Note that these prototypes are NOT included in VideoToolbox.h, since I did not
  15. want to include SANE.h there. Including SANE.h in a file has side effects that I
  16. wouldn't want to impose on all users of VideoToolbox.h.
  17.  
  18. Warning to MATLAB users: This file does NOT #include VideoToolbox.h
  19.  
  20. HISTORY:
  21. 12/91    dgp    wrote it.
  22. */
  23. #include <SANE.h>
  24. extended DoubleToExtended(double x);
  25. double ExtendedToDouble(extended x80);
  26. numclass ClassDouble(double x);
  27.  
  28. extended DoubleToExtended(double x)
  29. {
  30.     extended x80;
  31.     
  32.     if(sizeof(double)==sizeof(extended)) return *(extended *)&x;
  33.     else {
  34.         x96tox80((extended96 *)&x,&x80);
  35.         return x80;
  36.     }
  37. }
  38.  
  39. double ExtendedToDouble(extended x80)
  40. {
  41.     double x;
  42.  
  43.     if(sizeof(double)==sizeof(extended)) return *(double *)&x80;
  44.     else {
  45.         x80tox96(&x80,(extended96 *)&x);
  46.         return x;
  47.     }
  48. }
  49.  
  50. numclass ClassDouble(double x)
  51. {
  52.     return classdouble(DoubleToExtended(x));
  53. }
  54.  
  55.